package com.itbac.mybatisplusspringbootdemo.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * 自定义元对象处理程序
 * 处理自动填充
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 插入数据时填充
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        Object password = getFieldValByName("password", metaObject);
        if (null == password){
            setInsertFieldValByName("password", "123456", metaObject);
        }
    }

    /**
     * 更新数据时填充
     */
    @Override
    public void updateFill(MetaObject metaObject) {

    }
}
